/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//package server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

/**
 *
 * @author josegarcia
 */
public class ListThread extends Thread{
    private Socket socket=null;
    private ArrayList<Request> tasks;
    private Object lockTasks;
   
    public ListThread(Socket socket, ArrayList<Request> tasks, Object lockTasks) 
    {
    	super();
    	this.socket=socket;
    	this.tasks=tasks;
    	this.lockTasks=lockTasks;
    }
    public void run()
    {
    	try {
    	    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    	    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

    	    String inputLine, outputLine;
    	    KnockKnockProtocol kkp = new KnockKnockProtocol();
    	    outputLine = kkp.processInput(null);
    	    out.println(outputLine);
    	    String req=in.readLine();
    	    
    	    Request task=new Request(socket,req);
    	    synchronized(lockTasks){
    	    	tasks.add(task);
    	    	System.out.println("entro");
    	    	notifyAll();
    	    }
    	}catch(Exception e){
    		System.out.println("Error I/O");
    	}
	//notifyAll();
    }



}
